package com.magic.ch04_枚举模拟与排序.特别数的和;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            if (check(i)) {
                ans+=i;
            }
        }
        System.out.println(ans);
    }

    static boolean check(int i) {
        while (i > 0) {
            if (i % 10 == 2 || i % 10 == 0 || i % 10 == 1 || i % 10 == 9)
                return true;
            i /= 10;
        }
        return false;
    }
}
